package com.soar.recruitment.module.attention.ui.fragment;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.soar.recruitment.R;
import com.soar.recruitment.common.ui.fragment.SOARBaseFragment;
import com.soar.recruitment.common.ui.view.ptr.PtrFrameInit;
import com.soar.recruitment.common.ui.view.ptr.RecyclerViewInit;
import com.soar.recruitment.module.attention.dal.bean.AttentionModel;
import com.soar.recruitment.module.attention.ui.adapter.AttentionAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrHandler;

public class AttentionFragment extends SOARBaseFragment {

    @BindView(R.id.toolbar_title)
    TextView toolbar_title;
    @BindView(R.id.container_ptr_frame)
    PtrFrameLayout containerPtrFrame;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    private AttentionAdapter mAttentionAdapter;
    private List<AttentionModel> mAttentionModleList = new ArrayList<>();

    public static AttentionFragment newInstance() {
        Bundle args = new Bundle();
        AttentionFragment fragment = new AttentionFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int initLayout() {
        return R.layout.fragment_attention;
    }

    @Override
    public void initVariable() {

    }

    @Override
    public void initView(Bundle savedInstanceState) {
        toolbar_title.setText("关注");

        initRecycleView();

        mAttentionAdapter = new AttentionAdapter(_mActivity, R.layout.item_attention, mAttentionModleList);
        recyclerView.setAdapter(mAttentionAdapter);
    }

    /**
     * 初始化RecyclerView
     */
    private void initRecycleView() {
        PtrFrameInit.init(containerPtrFrame, mActivity, false);
        containerPtrFrame.setPtrHandler(new PtrHandler() {
            @Override
            public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
                return PtrDefaultHandler.checkContentCanBePulledDown(frame, recyclerView, header);
            }

            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {

            }
        });
        containerPtrFrame.disableWhenHorizontalMove(true);
        containerPtrFrame.autoRefresh(true);

        RecyclerViewInit.init(recyclerView, mActivity);
    }

    @Override
    public void initData() {
        AttentionModel attentionModel = null;
        for(int i = 0; i < 5; i++) {
            attentionModel = new AttentionModel();
            mAttentionModleList.add(attentionModel);
        }
        mAttentionAdapter.setData(mAttentionModleList);
    }
}
